<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div {
            width: 100px;
            height: 100px;
            background: red;
            margin-left: 200px;
            margin-top: 300px;
        }
    </style>
</head>

<body>
    <div>

    </div>

    <script>
        var div = document.querySelector("div")
        // 获取元素距离视口  距离
        var res = div.getBoundingClientRect()
        console.log(res)

    </script>
</body>

</html>